package com.wei.io;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import com.alibaba.fastjson.JSONObject;

import lombok.extern.log4j.Log4j;

@Log4j
public class SaveRecord {
	
	private final String path;
	
	public SaveRecord() {
		path = this.getClass().getClassLoader().getResource(MapConfigLoader.RECODE_NAME).getPath();
	}

	public void save(int index,int zoom) {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("index", index);
		jsonObject.put("zoom", zoom);
		FileOutputStream out = null;
		try {
			out = new FileOutputStream(new File(path));
			out.write(jsonObject.toJSONString().getBytes());
			out.flush();
		} catch (IOException e) {
			log.error("保存下载记录出现异常!", e);
		} finally {
			if(out != null) {
				try {
					out.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		
	}
	
}
